import http from 'src/framework/network/http'

export type Interface = {
    name: string
    code: string
    component?: () => Promise<any>
}

export const Interfaces = {
    停车_立方云: {
        name: '立方-云对接',
        code: 'P-LF-CP',
        component: () => import('./停车立方云/index.vue')
    },
    门禁_海康云: {
        name: '海康-云对接',
        code: 'EG-HK-CP',
        component: () => import('./门禁大华云/index.vue')
    },
    门禁_大华云: {
        name: '大华-云对接',
        code: 'EG-DH-CP',
        component: () => import('./门禁大华云/index.vue')
    },
    视频_海康云: {
        name: '海康-云对接',
        code: 'V-HK-CP',
        component: () => import('./视频大华云/index.vue')
    },
    视频_大华云: {
        name: '大华-云对接',
        code: 'V-DH-CP',
        component: () => import('./视频大华云/index.vue')
    },
    视频_局域网: {
        name: '局域网对接',
        code: 'V--INET',
        component: () => import('./视频局域网/index.vue')
    }
}

export function addVillageEquipConfig(params:{villageId: number, typeCode: string}) {
    return http.post('/resource/village/addVillageEquipConfig', Object.assign({
        dockType: params.typeCode.split('-')[0]
    }, params))
}

export function delVillageEquipConfig(params:{villageId: number, typeCode: string}) {
    return http.post('/resource/village/delVillageEquipConfig',Object.assign({
        dockType: params.typeCode.split('-')[0]
    }, params))
}

export async function villageEquipConfig(params: {villageId: number, dockType: 'EG'|'P'|'V'}) {
    const result = await http.post<Config[]>('/resource/village/getVillageEquipConfig', params)
    const infs = Object.values(Interfaces)
    return result.map(r => {
        return Object.assign({
            villageId: r.villageId
        }, infs.find(i => i.code === r.typeCode))
    })
}

export type Config = {
    typeCode: string
    villageId: number
}